import { Component, OnInit,Output,Input,EventEmitter,ViewChild } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-pstt',
  templateUrl: './pstt.component.html',
  styleUrls: ['./pstt.component.scss']
})
export class PsttComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService,public request:RequestService) {
    this.filed_tablelist();//表格字段动态列集合生成
    this.select_list();//下拉初始化数据
  }

  @Output()  private  outer=new EventEmitter();
  @Input() puc_msg:any; 
  
  isType=localStorage.getItem("isType");//登录用户权限A系统管理员，L组织管理员，S普通组织用户，AS 系统组织用户
  privIds=this.interfaceService.GetQueryString("privId")//当前访问目录节点权限id
  switchUnitId=localStorage.getItem("ownerId")
  ngOnInit() {
    // this.table();//初始化列表表格数据
    this.ss5="CN"
  }
  

  field1=[]     //table表格1-主表列字段集合
  data1={}      //table表格1-主表对象数据集合
  data1_dis={}  //table表格1-主表对象禁用集合
  data1_sel=[]  //table表格1-主表下拉框数据集合
  data1_att=[]  //table表格1-主表自定义属性数据集合
  
  /**
   * 表格字段动态列集合生成
   */
  filed_tablelist(){
    this.interfaceService.postPage("/erp/common/fields/getfieldsbytype",{"type":"warehouse.SttVO"}).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if(data.code==200){
        this.field1=this.utilService.filed_list(data.object);
        for(var i=0;i<data.object.length;i++){
          this.data1[data.object[i]["fieldValue"]]=""
		      this.data1_dis[data.object[i]["fieldValue"]]=true
        }
      }
    }
    });
    
  }


  /**
   * 下拉集合初始化数据
   */
  prodGrpBy_list
  select_list() {
    this.interfaceService.postPage("/erp/warehouse/stt/loadsttpulldown", {}).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if (data.code == 200) {
        for(let i in data.object){
          this.data1_sel[i]=data.object[i]
        }
      }
    }
    });
  }
  /**
   * 下拉数据添加时初始化默认取第一个值
   */
  select1_data(){
    this.interfaceService.selectIsValue(this, 1);
  }


  popup01_url='';
  popup01_para
  popup01 = false;
  /**
   * 
   * @param url 
   * @param progress 盘点表弹窗，编辑内容弹窗需携带赋值状态
   * @param warehCode 盘点表弹窗，编辑内容弹窗需携带赋值盘点表仓库内容
   */
  popup01_show(url,progress,warehCode): void {
    this.popup01_url=url
    this.ss5=progress
    this.ss4=warehCode
    this.popup01 = true;
    this.popup01_table();
  }
  popup01_hide(): void {
    this.popup01_url='';
    this.ss1 = '';
    this.ss2 = '';
    this.ss3 = '';
    this.ss4 = '';
    this.ss5 = null;
    this.popup01 = false;
  }
 

  ss1 = '';
  ss2 = '';
  ss3 = '';
  ss4 = '';
  ss5 = null;
  i=0
  popup01_table() {
    let Status=this.ss5==null?"":this.ss5
    this.listTable(this.popup01_url+"&sttNum=" + this.ss1 + "&minDocDate=" + this.ss2 + "&maxDocDate=" + this.ss3 + "&warehCode=" + this.ss4 + "&progress=" + Status + "&unitId=" + this.switchUnitId);
  }




  list1=0;
  listTable(url): void {
    setTimeout(() => {
      layui.use(['table',  'laydate'], (obj) => {
        var  table = layui.table,  laydate = layui.laydate;
        // laydate.render({
        //   elem: '#yearVal'
        //   , type: 'year'
        //   ,done: (value) => {
        //     this.yearVal=value; 
        //     }
        // });
        laydate.render({
          elem: '#date11'
          ,done: (value) => {
            this.ss2=value; 
            }
        });
        laydate.render({
          elem: '#date12'
          ,done: (value) => {
            this.ss3=value; 
            }
        });

        //数据表格实例化			
        var tab=this.utilService.getTable(url,"#popup01_tblist_pstt",this.field1)
        tab["title"]='盘点表数据表'
        table.render(tab);
        table.on('rowDouble(popup01_tblist_pstt)', (obj) => {        
          this.popup01_hide();
          this.outer.emit(obj.data)      
        });
        

      });

    }, 500);


  }


  //组织弹窗
  @ViewChild('unit2Child')  unit2:any; 
  popup02_id=0
  popup02_url=""
  popup02_uid=""
  popup02_show(id,type,value?): void {//组织通用组件，value没有值为弹窗事件，value有值为数据验证事件（光标离开事件）
    this.popup02_id=id
    this.popup02_url="&unitType="+type+"&switchUnitId="
    if(!this.utilService.patrn.test(value)||value==null||typeof(value) == "undefined"){
      this.popup02_url=this.popup02_url + this.switchUnitId
      this.unit2.popup01_show("/erp/unit/option/unitOption?1=1"+this.popup02_url);
    }else{
      this.unit2.popup001_show(this.switchUnitId,type,value);
    }
  }
  
  ss4Id=""; //采购商编号搜索存储id
  unit2Parent(e){		//接收子组件传递过来的数据
    e.unitId=e.unitId==null?"":e.unitId
    e.unitCode=e.unitCode==null?"":e.unitCode
    e.unitName=e.unitName==null?"":e.unitName 
    if (this.popup02_id == 1) {//仓库编号-搜索
      this.ss4   = e.unitCode;
    } 
  }




}
